package yuyicman.net 
{
	import flash.events.StatusEvent;
	import flash.net.LocalConnection;
	import yuyicman.debug.Debugger;
	
	/**
	 * ...
	 * @author Yuyic.
	 */
	public class BridgeConnection extends LocalConnection
	{
		
		public static const GC_AS3:String = "gc_as3";
		public static const GC_AS2:String = "gc_as2";
		
		private var _connectionName:String;
		
		public function BridgeConnection() 
		{
			this.allowDomain( "*" );
		}
		
		public function get connectionName():String {
			
			return _connectionName;
			
		}
		
		override public function connect( connectionName:String ):void {
			
			if ( this.connectionName == connectionName )
			return;
			
			this._connectionName = connectionName;
			this.addEventListener(StatusEvent.STATUS, statusEventHandler);
			
			super.connect(connectionName);
			
		}
		
		public function disconnect():void {
			
			if ( this.connectionName ) {
				
				try {
					this.close();
				}
				catch (e:Error) {
					
				}
				
				this.removeEventListener(StatusEvent.STATUS, statusEventHandler);
				this._connectionName = null;
				
			}
			
		}
		
		private function statusEventHandler( e:StatusEvent ):void {
			
			// debug
			
			Debugger.log( e.toString() );
			
			//dispatchEvent( e );
			
		}
		
	}

}